import requests
from bs4 import BeautifulSoup
import sqlite3
import time
import os

def LOG(msg):
    with open('README.md','a') as LOG:
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        LOG.write('|{}|{}|\n'.format(t,msg))

class VideoData:
    def __init__(self):
        self.Video = 'BV1j4411W7F7'  #【猛男版】新 宝 岛
        self.Bsite = 'https://www.bilibili.com/video/'
        self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'}

    def run(self):
        try:
            self.Requ = requests.get(url = self.Bsite+self.Video, headers = self.headers)
        except Exception as Error:
            LOG(Error)
        self.Soup = BeautifulSoup(self.Requ.text, 'lxml')
        self.Data = self.Soup.select('#viewbox_report > div > span.view')[0].attrs['title'].strip('总播放数')
        LOG(self.Data)
        os.system('git commit -a -m \'auto commit\' && git push origin master')

while True:
    VideoData().run()
    time.sleep(60)
